package view.mediator.weapon.long_sword
{
	import model.vo.weapon.BaseWeaponVo;
	import model.weapon.WeaponModel;
	
	import org.robotlegs.mvcs.StarlingMediator;
	
	import service.SQLService;
	
	import view.component.weapon.long_sword.LongSwordSearchView;
	import view.event.weapon.long_sword.LongSwordListViewEvent;
	import view.event.weapon.SearchResultListViewEvent;
	import view.event.weapon.WeaponSearchViewEvent;
	
	
	/**
	 * LongSwordSearchView界面中介
	 * @author £iang
	 * 
	 */	
	public class LongSwordSearchViewMediator extends StarlingMediator
	{
		//-----------------------------
		// variables
		//-----------------------------
		
		/** LongSwordSearchView */
		[Inject]
		public var longSwordSearchView:LongSwordSearchView;
		
		/** sqlService */
		[Inject]
		public var sqlService:SQLService;
		
		/** weaponModel */
		[Inject]
		public var weaponModel:WeaponModel;
		
		//-----------------------------
		// properties
		//-----------------------------
		
		//-----------------------------
		// setter&getter
		//-----------------------------
		
		//-----------------------------
		// methods
		//-----------------------------
		
		/**
		 * 注册函数 
		 * 
		 */		
		override public function onRegister():void
		{
			addViewListener( WeaponSearchViewEvent.SEARCH, searchHandler );
			addViewListener( SearchResultListViewEvent.DETAIL, getDetailHandler );
		}
		
		//-----------------------------
		// events
		//-----------------------------
		
		/**
		 * 处理请求查询太刀派发的消息 
		 * @param event 请求查询太刀时派发的消息 
		 * 
		 */		
		protected function searchHandler( event:WeaponSearchViewEvent ):void
		{
			var resultVec:Vector.<BaseWeaponVo> = sqlService.getShortWeaponSearchData(
				"long_sword", event.rank, event.awakeType, event.attribute, 
				event.add, event.blade, event.slot, event.sort
			);
			
			longSwordSearchView.resultView.setData( resultVec );
		}
		
		/**
		 * 处理请求获取详细信息后派发的事件 
		 * @param event 请求获取详细信息后派发的事件 
		 * 
		 */		
		protected function getDetailHandler( event:SearchResultListViewEvent ):void
		{
			weaponModel.curSearchWeaponId = event.weaponId;
			dispatch( new LongSwordListViewEvent( LongSwordListViewEvent.GET_DETAIL ) );
		}
		
		//-----------------------------
		// dispose
		//-----------------------------
		
		/**
		 * 移除函数 
		 * 
		 */		
		override public function onRemove():void
		{
			removeViewListener( WeaponSearchViewEvent.SEARCH, searchHandler );
			removeViewListener( SearchResultListViewEvent.DETAIL, getDetailHandler );
			super.onRemove();
		}
		
		//-----------------------------
		// construction
		//-----------------------------
		
		/**
		 * 构造函数
		 *
		 */
		public function LongSwordSearchViewMediator()
		{
			super();
		}
	}
}